package net.seninp.fdata.data;

import java.util.ArrayList;

public class Month {

  private Integer month;
  private ArrayList<Measurement> measurements;

  public Month(Integer month) {
    this.month = month;
    this.measurements = new ArrayList<Measurement>();
  }

  public void add(Measurement m) {
    this.measurements.add(m);
  }

  public int measurementsCount() {
    return this.measurements.size();
  }

  public Double getAverageEffort() {
    Double totalDays = 0D;
    for (Measurement m : measurements) {
      totalDays += m.getDays();
    }
    return totalDays / (double) measurements.size();
  }

  public double getAverageEffortForFishery(String fishery) {
    Double totalDays = 0D;
    int count = 0;
    for (Measurement m : measurements) {
      if (fishery.equalsIgnoreCase(m.getFisheryId())) {
        totalDays += m.getDays();
        count++;
      }
    }
    return totalDays / (double) count;
  }

  public Double getAverageCatch() {
    Double totalTons = 0D;
    for (Measurement m : measurements) {
      totalTons += m.getYft_c();
    }
    return totalTons / (double) measurements.size();
  }

  public double getAverageCatchForFishery(String fishery) {
    Double totalTons = 0D;
    int count = 0;
    for (Measurement m : measurements) {
      if (fishery.equalsIgnoreCase(m.getFisheryId())) {
        totalTons += m.getYft_c();
        count++;
      }
    }
    return totalTons / (double) count;
  }

  /**
   * Check if there is measurements for particular fishery.
   *
   * @param fishery
   * @return
   */
  public boolean hasMeasurements(String fishery) {
    for (Measurement m : this.measurements) {
      if (fishery.equalsIgnoreCase(m.getFisheryId())) {
        return true;
      }
    }
    return false;
  }

  public double getAverageEffectivenessForFishery(String fishery) {
    Double totalEfct = 0D;
    int count = 0;
    for (Measurement m : measurements) {
      if (fishery.equalsIgnoreCase(m.getFisheryId())) {
        totalEfct += m.getYft_c() / m.getDays();
        count++;
      }
    }
    return totalEfct / (double) count;
  }

}
